/*
 * frmCourses.java
 *
 * Created on April 28, 2010, 5:33 PM
 */
package GUI;

import Entity.Course;
import Interact.Courses;
import Validate_Connect.CheckForm;
import Validate_Connect.GUIInteraction;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author  Shinichi
 */
public class frmCourses extends javax.swing.JInternalFrame {

    /** Creates new form frmCourses */
    public frmCourses() {
        initComponents();
        try {
            GUIInteraction.readToTable("select * from tblCourses", _tblCoursesList);
        } catch (SQLException ex) {
            Logger.getLogger(frmCourses.class.getName()).log(Level.SEVERE, null, ex);
        }
        _txtCoursesID.setEditable(false);
        _txtCoursesName.setEditable(false);
        _txtDescription.setEditable(false);
        _btnreset.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        _txtDescription = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        _txtCoursesID = new javax.swing.JTextField();
        _txtCoursesName = new javax.swing.JTextField();
        _btndelete = new javax.swing.JButton();
        _btnaddNew = new javax.swing.JButton();
        _btnreset = new javax.swing.JButton();
        _btnupdate = new javax.swing.JButton();
        _btnclose = new javax.swing.JButton();
        _btnprint = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        _tblCoursesList = new javax.swing.JTable(){
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;   //Disallow the editing of any cell
            }
        };
        _tblCoursesList.getTableHeader().setReorderingAllowed(false);
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("AITSM - Courses");

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Information"));

        jLabel3.setText("Description:");

        jScrollPane1.setViewportView(_txtDescription);

        jLabel1.setText("Courses ID:");

        jLabel2.setText("Course Name:");

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(36, 36, 36)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel3))
                .add(22, 22, 22)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(_txtCoursesName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 166, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 253, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(_txtCoursesID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(_txtCoursesID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(_txtCoursesName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(43, 43, 43)
                        .add(jLabel3))
                    .add(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        _btndelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Delete2.png"))); // NOI18N
        _btndelete.setText("Delete");
        _btndelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btndeleteActionPerformed(evt);
            }
        });

        _btnaddNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/list_add2.png"))); // NOI18N
        _btnaddNew.setText("Add New");
        _btnaddNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnaddNewActionPerformed(evt);
            }
        });

        _btnreset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/reset2.png"))); // NOI18N
        _btnreset.setText("Reset");
        _btnreset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnresetActionPerformed(evt);
            }
        });

        _btnupdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/update2.png"))); // NOI18N
        _btnupdate.setText("Update");
        _btnupdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnupdateActionPerformed(evt);
            }
        });

        _btnclose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/Logout16x16.png"))); // NOI18N
        _btnclose.setText("Close");
        _btnclose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btncloseActionPerformed(evt);
            }
        });

        _btnprint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Image/printer2.png"))); // NOI18N
        _btnprint.setText("Print");
        _btnprint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _btnprintActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Courses List"));

        _tblCoursesList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        _tblCoursesList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                _tblCoursesListMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(_tblCoursesList);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
        );

        jPanel4.setBackground(new java.awt.Color(0, 153, 153));

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Courses");

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(364, 364, 364)
                .add(jLabel4)
                .addContainerGap(333, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jLabel4)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(10, 10, 10)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, _btndelete, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, _btnaddNew))
                        .add(30, 30, 30)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(_btnreset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_btnupdate, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(27, 27, 27)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(_btnclose, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(_btnprint, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 104, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btnaddNew)
                            .add(_btnreset)
                            .add(_btnprint))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(_btndelete)
                            .add(_btnupdate)
                            .add(_btnclose))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void _btnaddNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnaddNewActionPerformed
    if (_btnaddNew.getText().equals("Add New")) {
        resetForm();
        _txtCoursesID.setEditable(true);
        _txtCoursesName.setEditable(true);
        _txtDescription.setEditable(true);
        _btnaddNew.setText("Save");
        _txtCoursesID.requestFocus();
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(false);
    } else {
        if (!validateCourses()) {
            return;
        }
        Entity.Course _cou = new Course();
        _cou.set_CoursesID(_txtCoursesID.getText());
        _cou.set_CoursesName(_txtCoursesName.getText());
        _cou.set_Description(_txtDescription.getText());
        Interact.Courses.insertCourse(_cou);
        JOptionPane.showMessageDialog(null, "Addnew Succesfull", "Message", JOptionPane.INFORMATION_MESSAGE);
        resetForm();
        refresh();
        _txtCoursesID.setEditable(false);
        _txtCoursesName.setEditable(false);
        _txtDescription.setEditable(false);
        _btndelete.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btnupdate.setEnabled(false);
        _btnclose.setEnabled(true);
        _btnaddNew.setText("Add New");
    }

}//GEN-LAST:event__btnaddNewActionPerformed

private void _btnresetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnresetActionPerformed
    resetForm();
    _txtCoursesID.setEditable(false);
    _txtCoursesName.setEditable(false);
    _txtDescription.setEditable(false);
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btnresetActionPerformed

private void _btncloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btncloseActionPerformed

    this.dispose();

}//GEN-LAST:event__btncloseActionPerformed

private void _btndeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btndeleteActionPerformed
    String _id = _txtCoursesID.getText();
    int i = JOptionPane.showConfirmDialog(null, "Do you want to delete " + _txtCoursesName.getText(), "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
    if (i == 0) {
        Courses.deleteCourse(_id);
    }
    resetForm();
    refresh();
    _btnreset.setEnabled(false);
    _btndelete.setEnabled(false);
    _btnupdate.setEnabled(false);
}//GEN-LAST:event__btndeleteActionPerformed

private void _btnupdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnupdateActionPerformed
    if (_btnupdate.getText().equals("Update")) {
        _txtCoursesID.setEditable(true);
        _txtCoursesName.setEditable(true);
        _txtDescription.setEditable(true);
        _btnaddNew.setEnabled(false);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(false);
        _btndelete.setEnabled(false);
        _btnupdate.setText("Save");
        _txtCoursesID.requestFocus();
    } else {
        Entity.Course _cou = new Course(_txtCoursesID.getText(), _txtCoursesName.getText(), _txtDescription.getText());
        Interact.Courses.updateCourse(_cou);
        refresh();
        resetForm();
        _txtCoursesID.setEditable(false);
        _txtCoursesName.setEditable(false);
        _txtDescription.setEditable(false);
        _btnaddNew.setEnabled(true);
        _btnreset.setEnabled(false);
        _btnprint.setEnabled(true);
        _btndelete.setEnabled(false);
        _btnupdate.setEnabled(false);
        _btnupdate.setText("Update");
    }


}//GEN-LAST:event__btnupdateActionPerformed

private void _btnprintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__btnprintActionPerformed
    ConnectDB.ConnectDB.runReport("src\\Report\\reportCoursesList.jasper");
}//GEN-LAST:event__btnprintActionPerformed

private void _tblCoursesListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event__tblCoursesListMouseClicked
    int i = _tblCoursesList.getSelectedRow();
    _txtCoursesID.setText(String.valueOf(_tblCoursesList.getValueAt(i, 0)));
    _txtCoursesName.setText(String.valueOf(_tblCoursesList.getValueAt(i, 1)));
    _txtDescription.setText(String.valueOf(_tblCoursesList.getValueAt(i, 2)));
    _btnreset.setEnabled(true);
    _btndelete.setEnabled(true);
    _btnupdate.setEnabled(true);
    _btnprint.setEnabled(true);
    _btnclose.setEnabled(true);
    _txtCoursesID.setEditable(false);
    _txtCoursesName.setEditable(false);
    _txtDescription.setEditable(false);
    if (_btnaddNew.getText().equals("Save")) {
        _btnaddNew.setText("Add New");
    }
    if(_btnupdate.getText().equals("Save")){
        _btnupdate.setText("Update");
    }
    _btnaddNew.setEnabled(true);
}//GEN-LAST:event__tblCoursesListMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton _btnaddNew;
    private javax.swing.JButton _btnclose;
    private javax.swing.JButton _btndelete;
    private javax.swing.JButton _btnprint;
    private javax.swing.JButton _btnreset;
    private javax.swing.JButton _btnupdate;
    private javax.swing.JTable _tblCoursesList;
    private javax.swing.JTextField _txtCoursesID;
    private javax.swing.JTextField _txtCoursesName;
    private javax.swing.JTextPane _txtDescription;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

    public void resetForm() {
        _txtCoursesID.setText("");
        _txtCoursesName.setText("");
        _txtDescription.setText("");
    }

    public boolean validateCourses() {
        if (!CheckForm.isEmpty(_txtCoursesID.getText())) {
            JOptionPane.showMessageDialog(null, "Please Enter Courses ID", "Error", JOptionPane.ERROR_MESSAGE);
            _txtCoursesID.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtCoursesName.getText())) {
            JOptionPane.showMessageDialog(null, "Please Enter Courses Name", "Error", JOptionPane.ERROR_MESSAGE);
            _txtCoursesName.requestFocus();
            return false;
        }
        if (!CheckForm.isEmpty(_txtDescription.getText())) {
            JOptionPane.showMessageDialog(null, "Please Enter Description", "Error", JOptionPane.ERROR_MESSAGE);
            _txtDescription.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtCoursesID.getText(), "select * from tblCourses", "CoursesID")) {
            JOptionPane.showMessageDialog(null, "Courses ID is duplacate", "Error", JOptionPane.ERROR_MESSAGE);
            _txtCoursesID.requestFocus();
            return false;
        }
        if (!GUIInteraction.checkDuplicateID(_txtCoursesName.getText(), "select * from tblCourses", "CoursesName")) {
            JOptionPane.showMessageDialog(null, "Courses Name is Duplicate", "Error", JOptionPane.ERROR_MESSAGE);
            _txtCoursesName.requestFocus();
            return false;
        }
        return true;
    }

    public void refresh() {
        try {
            GUIInteraction.readToTable("select * from tblCourses", _tblCoursesList);
        } catch (SQLException ex) {
            Logger.getLogger(frmCourses.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
